﻿
function fnCustomCheck() {
    var ckeditorHTML = this.editor.document.getBody().getHtml().replace(/\r\n/g, "");

    document.getElementsByName("Contents")[0].value = ckeditorHTML;
    return "";
}

//获取url里的参数值 name:参数名称
function getPar(source, name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source))
        return RegExp.$2;
    return "";
};

//双击事件
function CustomDbClick() {
    if (typeof (fnCustomEdit) == "function") {
        fnCustomEdit();
    }
}
//----------------------------------------------

//增加
var fnCustomAdd = function () {
    var deptId = "";
    //
    var const_EditEntity = "tmInformation";
    var pagetitle = "培训资料添加";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&deptId=" + deptId));
    parent.NeedRefreshPage = this;
    //    var empName = getPar(decodeURI(location.href), "empName");
    //    var empId = getPar(decodeURI(location.href), "empId");
    //    var deptName = getPar(decodeURI(location.href), "deptName");
    //    var postName = getPar(decodeURI(location.href), "postName");
    //    document.getElementById("dialog1_h").innerHTML = "新增兼职岗位——" + empName;
    //    document.getElementById("EditUIWindow").src = "../EHR/hrAddPartTimePost.aspx?empId=" + empId + "&deptName=" + deptName + "&postName=" + postName;
    //    SetDWH(500, 300, YAHOO.example.container.dialog1);
    //    YAHOO.example.container.dialog1.show();
}
//编辑
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var const_EditEntity = "tmInformation";
    var pagetitle = "培训资料修改";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID) + ""));
    parent.NeedRefreshPage = this;

    //    var empName = getPar(decodeURI(location.href), "empName");
    //    var empId = getPar(decodeURI(location.href), "empId");
    //    var deptName = getPar(decodeURI(location.href), "deptName");
    //    var postName = getPar(decodeURI(location.href), "postName");
    //    document.getElementById("dialog1_h").innerHTML = "修改兼职岗位——" + empName;
    //    document.getElementById("EditUIWindow").src = "../EHR/hrAddPartTimePost.aspx?empId=" + empId + "&deptName=" + deptName + "&postName=" + postName + "&id=" + record.getData(const_entityID);
    //    SetDWH(500, 300, YAHOO.example.container.dialog1);
    //    YAHOO.example.container.dialog1.show();
}
//删除
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }

    var const_EditEntity = "tmInformation";

    var list = mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }
//    if (elist.length == 0) {
//        var recordID = myDataTable.getSelectedRows()[0];
//        record = myDataTable.getRecord(recordID);
//        SaveUrl = "AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=hrEmployeePositions&id=" + record.getData(const_entityID);
//    }
//    else {
//        SaveUrl = "AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=hrEmployeePositions&json=" + elist.join(",");
    //    }
    SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID);
    YAHOO.example.container.dialog3.show();
}

//初始化内置页面时
if (typeof ($) != "undefined") {
    $(document).ready(function () {
//        if (getPar1('id') == "") {
//            //alert(parent.parent.getPar1('id'));
//            instance[0].EmployeeID = parent.parent.getPar1('id');
//        }
    });
}